package com.ls.aicoderbackend.core.saver;

import cn.hutool.core.util.ObjUtil;
import com.ls.aicoderbackend.ai.model.HtmlCodeResult;
import com.ls.aicoderbackend.exception.BusinessException;
import com.ls.aicoderbackend.exception.ErrorCode;
import com.ls.aicoderbackend.model.enums.CodeGenTypeEnum;

public class HtmlFileSaveTemplate extends CodeFileSaveTemplate<HtmlCodeResult> {
    @Override
    protected void saveFile(HtmlCodeResult result, String baseDirPath) {
        writeToFile(baseDirPath, "index.html", result.getHtmlCode());
    }

    @Override
    protected CodeGenTypeEnum getBizType() {
        return CodeGenTypeEnum.HTML;
    }

    @Override
    protected void validateInput(HtmlCodeResult result) {
        super.validateInput(result);
        if (ObjUtil.isNull(result.getHtmlCode())) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "htmlCode为空");
        }
    }
}
